package com.easylinkin.linkappapi.quality.controller;

/**
 * @Author: kan yuanfeng
 * @Date: 2022/8/19 14:38
 * @Description: 台账
 */

import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.quality.dto.QualityQuestionInfoDto;
import com.easylinkin.linkappapi.quality.dto.QualityQuestionStatisticsDTO;
import com.easylinkin.linkappapi.quality.service.QualityInspectionAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: 质量检查台账
 */
@RestController
@RequestMapping("openapi/qualityInspectionAccount")
@Api(tags = "质量检查台账")
public class QualityInspectionAccountOpenApiController {
  @Autowired
  private QualityInspectionAccountService qualityInspectionAccountService;

  /**
   * @Description: 查询质量台账列表
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping("list")
  @ApiOperation("根据条件，分页(不分页)查询")
  public RestMessage queryListByPage(@RequestBody RequestModel<QualityQuestionInfoDto> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<QualityQuestionInfoDto> record =  qualityInspectionAccountService.queryOpenApiListByPage(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }

  @GetMapping("{id}")
  @ApiOperation("质量台账详细")
  public RestMessage findById(@PathVariable("id")Integer id,Integer type){
    Assert.notNull(id, "id不能为空");
    Assert.notNull(type, "type不能为空");
    QualityQuestionInfoDto qualityQuestionInfoDto =  qualityInspectionAccountService.findById(id,type);
    return RestBuilders.successBuilder().data(qualityQuestionInfoDto).build();
  }

  @PostMapping("getCount")
  @ApiOperation("根据时间进行统计结果")
  public RestMessage getCount(@RequestBody QualityQuestionInfoDto qualityQuestionInfoDto){
    if(CollectionUtil.isEmpty(qualityQuestionInfoDto.getProjectIds())){
      return null;
    }
    JSONObject openApiCount = qualityInspectionAccountService
        .getOpenApiCount(qualityQuestionInfoDto);
    return RestBuilders.successBuilder().data(openApiCount).build();
  }

}
